<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>库存调拨</title>
		<link rel="stylesheet" type="text/css" href="../../layui/css/layui.css" />
		<style>
			/*表体宽和位置的设置*/
			.repertoryAllotAndReceiptsParticulars>div>table+div{
				width: 815px;
				margin: 0px auto 5px;
			}

			/*表头居中、高和行高的设置*/
			.repertoryAllotAndReceiptsParticulars>div>table+div div table tr th div,
			#currentTableId+div div table tr th div{
				text-align: center;
			}

			/*表体字体大小 、居中、高和行高的设置*/
			.repertoryAllotAndReceiptsParticulars>div>table+div div table tr td div,
			 #currentTableId+div div table tr td div{
				text-align: center;
			}

			/*表头居中、高和行高的设置*/
			.commodityBatchInfo>div>table+div div table tr th div {
				text-align: center;
				padding: 0px;
			}
			/*表体字体大小 、居中、高和行高的设置*/
			.commodityBatchInfo>div>table+div div table tr td div {
				text-align: center;
				padding: 0px;
			}

			/*表头居中、高和行高的设置*/
			.commodityBatch>div>table+div div table tr th div {
				text-align: center;
				padding: 0px;
			}
			/*表体字体大小 、居中、高和行高的设置*/
			.commodityBatch>div>table+div div table tr td div {
				text-align: center;
				padding: 0px;
			}


		</style>
	</head>

	<body>
		<div class="layui-tab">
			<ul class="layui-tab-title ">
				<li class="layui-this">库存调拨单</li>
				<li>库存调拨情况</li>
			</ul>

			<div class="layui-tab-content" style="padding-top: 0px;">
				<!--库存调拨单-->
				<div class="layui-tab-item layui-show" style="padding:0px 20px">

					<!-- 标题 -->
					<div style=" margin:5px 0px;">
						<h1 style="text-align: center; ">库存调拨</h1>
						<div style="text-align: right;">
							<span style="color:red;">单号:</span>
							<span class="oddNumbers" style="color:red;"></span>
						</div>
					</div>

					<!-- 三个按钮 -->
					<div class="layui-form layui-panel" style="display: flex; justify-content: space-around;">
						<div class="layui-inline" style="text-align: center;">
							<label class="layui-form-lable">调出仓库:</label>
							<div class="layui-input-inline">
								<select id="transferOutOfWarehouse" lay-filter="watch">
								</select>
							</div>
						</div>
						<div class="layui-inline" style="text-align: center;">
							<label class="layui-form-lable">调入仓库:</label>
							<div class="layui-input-inline">
								<select id="transferIntoWarehouse">
								</select>
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">调入日期:</label>
							<div class="layui-input-inline">
								<input type="text" class="layui-input" id="allotDate">
							</div>
						</div>
					</div>

					<!--表格主体信息-->
					<table class="layui-hide" id="currentTableId" lay-filter="currentTableId"></table>

					<!--尾部-->
					<div class="layui-form">
						<label class="layui-form-lable" style="margin-left: 20px;">经办人:</label>
						<div class="layui-input-inline">
							<select name="" id="employee">
							</select>
						</div>

						<label class="layui-form-lable" style="margin-left: 30px;">备注:</label>
						<div class="layui-input-inline" style="margin-right: 90px;">
							<input type="text" style="height: 30px; width: 700px;" id="invAllotComment" autocomplete="off" value="&nbsp;"/>
						</div>

						<!--确认与退出按钮-->
						<div class="layui-input-inline">
							<button class="layui-btn layui-btn-radius layui-btn-sm" id="affirmbtn">确认</button>
							<!--<button class="layui-btn layui-btn-radius layui-btn-sm" style="background-color: red;">退出</button>-->
						</div>
					</div>
				</div>

				<!--库存调拨情况-->
				<div class="layui-tab-item">
					<!--调拨时间查询-->
					<div class="layui-fluid" style="text-align: center; margin: 5px 0px;">
						<div class="layui-form layui-inline" style="margin:0px;">
							<div class="layui-form-item" style="margin:0px;">
								<div class="layui-inline" style="margin:0px;">
									<label class="layui-form-label" style="width:100px;">查询日期范围</label>
									<div class="layui-input-inline">
										<input type="text" class="layui-input" id="shijiansan" autocomplete="off" placeholder=" - "/>
									</div>
								</div>
							</div>
						</div>
						<button class="layui-btn layui-btn-radius layui-btn-normal layui-btn-sm" id="allotData">查询</button>
					</div>

					<div class="layui-fluid " style="text-align: center;">
						<form class="layui-form layui-input-inline">
							<div class="layui-input-inline">
								<label class="layui-form-lable">调出仓库:</label>
								<div class="layui-input-inline">
									<select id="transferOutOfWarehouses">
										<option>所有仓库</option>
									</select>
								</div>
							</div>
							<div class="layui-input-inline">
								<label class="layui-form-lable">调入仓库:</label>
								<div class="layui-input-inline">
									<select id="transferIntoWarehouses">
										<option>所有仓库</option>
									</select>
								</div>
							</div>
							<div class="layui-input-inline">
								<label class="layui-form-lable">经办人:</label>
								<div class="layui-input-inline">
									<select id="employees">
										<option>所有经办人</option>
									</select>
								</div>
							</div>
						</form>

						<button class="layui-btn layui-btn-radius layui-btn-normal layui-btn-sm" id="advancedQuerybtn">高级查询</button>
					</div>

					<!--库存调拨列表和单据详情-->
					<div class="layui-fluid">
						<fieldset class="table-search-fieldset repertoryAllotAndReceiptsParticulars" style="width:1000px;margin: 0px auto;">
							<legend style="margin-left: 15px;">库存调拨列表</legend>

							<div style="width:815px; margin:0px auto;">
								<!--库存调拨表的主体信息-->
								<table class="layui-hide" id="repertoryAllot" lay-filter="repertoryAllot"></table>
							</div>

							<div id="receiptsInfo">
								<span class="layui-inline" style="margin-left:100px; margin-bottom:4px;">单据的详情信息:</span>
								<span style="color: red;"></span>
							</div>

							<div style="width:815px; margin:0px auto;">
								<!--库存调拨表的主体信息-->
								<table class="layui-hide" id="receiptsParticulars" lay-filter="currentTableFilter"></table>
							</div>
						</fieldset>
					</div>
				</div>
			</div>
		</div>

		<!--增加商品(库存调拨)弹窗-->
		<div id="commodityInformationPopup" style="padding:0px 5px; display: none;">
			<form class="layui-form" lay-filter="InformationPopup">
				<fieldset class="table-search-fieldset" style="width: 580px;">
					<legend style="margin-left: 15px;">查询商品列表</legend>

					<div class="layui-inline" style="width:250px;margin-left:70px;">
						<div>
							<span>商品编号：</span>
							<input type="text" name="proId" class="layui-input-inline" readonly style="border:none; width:170px;margin-bottom:2px"/>
						</div>
						<div>
							<span>规格型号：</span>
							<input type="text" name="inveDescSize" class="layui-input-inline" readonly style="border:none; width:170px;margin-bottom:5px"/>
						</div>
						<div>
							<span>当前库存：</span>
							<input type="text" id="inveDescInventoryNum" name="inveDescInventoryNum" class="layui-input-inline" readonly style="border:none; width:170px;margin-bottom:1px"/>
						</div>
						<div>
							<span>生产厂商：</span>
							<input type="text" name="inveDescManufacturer" class="layui-input-inline" readonly style="border:none; width:170px;margin-bottom:5px"/>
						</div>
					</div>

					<div class="layui-inline">
						<div>
							<span>商品名称：</span>
							<input type="text" name="inveDescName" class="layui-input-inline" readonly style="border:none; width:180px;margin-bottom:5px"/></div>
						<div>
							<span style="margin-left:28px;">单位：</span>
							<input type="text" name="inveDescUnit" class="layui-input-inline" readonly style="border:none;width:120px;margin-bottom:5px"/>
						</div>
						<div>
							<span>批注文号：</span>
							<input type="text" name="inveDescPostil" class="layui-input-inline" readonly style="border:none;width:120px;margin-bottom:5px"/></div>
						<div>
							<span style="margin:0px 0px 0px 14px;">保质期：</span>
							<input type="text" id="quality" class="layui-input-inline" readonly style="border:none;width:120px;"/>
						</div>
					</div>
					<hr/>

					<div class="layui-inline">
						<div>
							<label class="layui-form-lable" style="margin-left: 100px;">数量:</label>
							<div class="layui-input-inline">
								<input type="number" name="inveDescNum" id="number" style="height:20px; width:100px;" value="1" min="1"/>
							</div>

							<label class="layui-form-lable" style="margin-left:80px;">产品批次:</label>
							<div class="layui-input-inline">
								<input type="text" name="inveDescBatchNum" id="inveDescBatchNum" class="layui-input-inline"
									   readonly style="height:20px; width:100px;text-indent:10px; border:none;"/>
							</div>
						</div>

						<div class="layui-inline" style="margin: 10px 0px 10px 70px;">
							<span>生产日期：</span><input type="text" name="inveDescStartDate" id="inveDescStartDate" class="layui-input-inline" readonly style="border:none; width:120px;margin-bottom:2px"/>
						</div>

						<div class="layui-inline" style="margin: 10px 0px 10px 72px;">
							<span>有效期：</span><input type="text" name="inveDescValidityDate" id="inveDescValidityDate" class="layui-input-inline" readonly
													style="border:none; width:120px;margin-bottom:2px;text-indent:5px;"/>
						</div>
					</div>
				</fieldset>

				<div class="confirmCancelButton" style="text-align:center;">
					<button type="button" class="layui-btn layui-btn-radius layui-btn-normal layui-btn-sm" style="margin: 10px 150px 0px 0px;">确认</button>
					<button type="button" class="layui-btn layui-btn-radius layui-btn-normal layui-btn-sm" style="margin-top: 10px;">取消</button>
				</div>

				<div>
					<span>商品批次信息</span>
					<fieldset class="table-search-fieldset commodityBatchInfo" style="width:577px; padding:0px 2px;">
						<legend style="margin-left: 15px;">可以在下面列表中选择不同批次的商品</legend>

						<div class="layui-tab-item layui-show">
							<!--商品批次信息-->
							<table class="layui-hide" id="commodityBatch" lay-filter="commodityBatchInfoFilter"></table>
						</div>
					</fieldset>
				</div>

				<!--隐藏的所需信息-->
				<div class="layui-inline" style="display:none;">
					<input type="text" name="inveDescPrice" id="inveDescPrice" class="layui-input-inline" readonly />
				</div>
				<div class="layui-inline" style=" display:none;">
					<input type="text" name="totalMoney" id="totalMoney" class="layui-input-inline" readonly/>
				</div>
				<div class="layui-inline" style=" display:none;">
					<input type="text" name="inveDescType" id="inveDescType" class="layui-input-inline" readonly/>
				</div>
				<div class="layui-inline" style=" display:none;">
					<input type="text" name="inveDescPostil" id="inveDescPostil" class="layui-input-inline" readonly/>
				</div>
				<div class="layui-inline" style=" display:none;">
					<input type="text" name="inveDescProState" id="inveDescProState" class="layui-input-inline" readonly/>
				</div>
				<div class="layui-inline" style=" display:none;">
					<input type="text" name="inveDescComment" id="inveDescComment" class="layui-input-inline" readonly/>
				</div>
				<div class="layui-inline" style=" display:none;">
					<input type="text" name="supId" id="supId" class="layui-input-inline" readonly/>
				</div>
				<div class="layui-inline" style=" display:none;">
					<input type="text" name="inveDescDepot" id="inveDescDepot" class="layui-input-inline" readonly/>
				</div>
			</form>
		</div>

		<!--调拨商品表格头部信息-->
		<script type="text/html" id="toolbarDemo">
			<div class="layui-btn-container">
				<button class="layui-btn  layui-btn-radius" lay-event="add">添加商品</button>
				<button class="layui-btn  layui-btn-radius" style="display:none;" lay-event="deleteItem">删除商品</button>
				<button class="layui-btn  layui-btn-radius" style="display:none;" lay-event="modifyProduct">修改商品</button>
			</div>
		</script>

		<!--所选商品的删除按钮的弹窗-->
		<div id="whetherDelete" style="display:none;">
			<div style="text-align:center;margin: 40px 0px 40px 0px">是否删除该商品信息？</div>
			<div style="text-align: center;">
				<button class="layui-btn layui-btn-radius layui-btn-normal layui-btn-sm">是</button>
				<button class="layui-btn layui-btn-radius layui-btn-normal layui-btn-sm">否</button>
			</div>
		</div>

		<script src="../../layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script>
            /*临时存放要交互的数据*/
            var temporaryStorageArrays = [];
            var depotName;

			layui.use(['form', 'table', 'laydate'], function() {
				var $ = layui.jquery,
					form = layui.form,
					table = layui.table;
				var laydate = layui.laydate;


                /*获取当前时间
                YYYY-mm-dd HH:MM表示2019-06-15 19:45
                YYYY 2019
                mm 06
                dd 15
                mm-dd 06-15
                *@description: eg:let date = new Date(); dateFormat("YYYY-mm-dd HH:MM", date) 2019-06-06 19:45
                *console.log(this.dateFormat("YYYY-mm-dd HH:MM", new Date())) //this.dateFormat() 2021-10-29 15:27
                   *console.log(this.dateFormat("YYYY/mm/dd", new Date())) //this.dateFormat() 2021/10/29
                *console.log(this.dateFormat("YYYYmmddHHMM", new Date())) //this.dateFormat() 202110291517
                */
                /*产生随机单号*/
                var randomOdd = function () {
                    var dateFormat = function(fmt,date){
                        var ret;
                        const opt = {
                            "Y+": date.getFullYear().toString(),        // 年
                            "m+": (date.getMonth() + 1).toString(),     // 月
                            "d+": date.getDate().toString(),            // 日
                            "H+": date.getHours().toString(),           // 时
                            "M+": date.getMinutes().toString(),         // 分
                            "S+": date.getSeconds().toString()          // 秒
                            // 有其他格式化字符需求可以继续添加，必须转化成字符串
                        };
                        for (var k in opt) {
                            ret = new RegExp("(" + k + ")").exec(fmt);
                            if (ret) {
                                fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
                            };
                        };
                        return fmt;
                    }
                    var day = dateFormat("YYYYmmddHHMMSS", new Date());
                    day = "DB"+day;
                    $('.oddNumbers').html(day);
                }
                randomOdd();


				//常规日期
				laydate.render({
					elem: '#allotDate',
					value: getDay(0)
				});

				//日期范围
				laydate.render({
					elem: '#shijiansan',
					range: true
				});

				/*修改的弹窗*/
                function addhotd(data) {
                    index = layer.open({
                        type: 1,
                        title: '商品信息(库存调拨)',
                        content: $('#commodityInformationPopup'),
                        area: ["600px", "560px"],
						success:function () {
							form.val('InformationPopup',data);
                        }
                    })
                };

                /*判断调拨数量的范围*/
                $('#number').bind('input',function () {
                    var number = +$('#number').val();
                    /*库存数量*/
                    /*调拨数量不能小于一*/
                    if(number < 0 ){
                        $('#number').val(1);
                    }
                });

                /*商品清单点击查询出来的数据 临时存放的变量名*/
                var row;
                /*商品信息（库存调拨）弹窗退出按钮时用的变量名*/
                var index;
                /*调拨数量*/
                var number;
                /*库存数量*/
                var stockNumber;
                /*表格这一行的下标*/
                var surfaceIndex = 0 ;

                /*关闭商品信息（库存调拨）弹窗*/
                function exit() {
                    layer.close(index);
                }

                /*点击商品信息（库存调拨）弹窗取消按钮*/
                $('.confirmCancelButton>button:nth-of-type(2)').click(function () {
                    exit();
                });

                /*系统提示库存数量小于调拨数量*/
                var inventoryQuantityPrompt = function () {
                    layer.open({
                        type:0,
                        title:'系统提醒',
                        content:'库存数量小于调拨数量,不允许调拨!'
                    });
                }


                /*点击商品信息（库存调拨）弹窗的确认按钮*/
                $('.confirmCancelButton>button:nth-of-type(1)').click(function () {
                    number = +$('#number').val();
                    stockNumber = row.inveDescInventoryNum;


                    if(number == 0){
                        $('#number').val(1);
                        number = +$('#number').val();
					}

                    if(number <= stockNumber){
                        exit();
                        $('#totalMoney').val(number * row.inveDescPrice);
                        temporaryStorageArrays[surfaceIndex] = form.val('InformationPopup');
                        table.reload('currentTableId',{
                            data: temporaryStorageArrays
                        });
                    }else if(stockNumber == 0){
                        layer.open({
                            type:0,
                            title:'系统提醒',
                            content:'抱歉,该批次的商品已经销完了!'
                        });
					} else{
                        inventoryQuantityPrompt();
                        $('#number').val(stockNumber);
                    }
                    amendAnddelete();
                });



                /*库存调拨的商品列表添加样式*/
                /*单击*/
				table.on('row(currentTableId)', function(obj){
                    obj.tr.addClass('layui-bg-green').siblings().removeClass('layui-bg-green');
                    surfaceIndex = obj.tr.attr('data-index');
                    row = obj.data;
				});

                /*双击*/
                table.on('rowDouble(currentTableId)', function(obj){
                    addhotd(row);
                    commodityBatchSurface();
                });

                /*确认按钮*/
                $('#affirmbtn').click(function () {
                    /*单号*/
					var invAllotld = $('.oddNumbers').html();
					/*调出仓库id存入mysql的*/
                    depotIdOut = $('#transferOutOfWarehouse~div .layui-this').attr('lay-value');
                    /*调入仓库id存入mysql的*/
                    depotIdIn = $('#transferIntoWarehouse~div .layui-this').attr('lay-value');
                    /*调拨日期*/
                    allotData = $('#allotDate').val();
                    /*经办人和操作员*/
                    empId = $('#employee').val();
                    /*备注*/
                    var invAllotComment = $('#invAllotComment').val();


                    /*判断是否有数据可以被调拨*/
                    if(temporaryStorageArrays.length <= 0 ){
                        layer.open({
                            type:0,
                            title:'系统提醒',
                            content:'单据没有业务发生不能保存!'
                        });
					}else{
                        //转成JSON字符串格式后去除 '[' 与 ']'
                        temporaryStorageArrays = JSON.stringify(temporaryStorageArrays).replace('[','').replace(']','');
						/*新增一条调拨信息*/
                        $.ajax({
                            type:"GET",
                            url:"/updateInventoryAllocation/"+invAllotld+"/"+depotIdOut+"/"+depotIdIn+"/"+allotData+"/"+
                            empId+"/"+invAllotComment
                        });

                        /*新增调拨明细表信息*/
                        $.ajax({
							type: "GET",
							url: "/updateInventoryAllocationDesc/"+temporaryStorageArrays+"/"+invAllotld
						});

                        /*修改调出仓库被调出的商品信息*/
                        $.ajax({
                            type: "GET",
                            url: "/updateInventoryAllocationDescOut/"+temporaryStorageArrays
                        });

                        /*修改调出仓库被调出的商品信息*/
                        $.ajax({
							type: "GET",
							url: "/updateInventoryDescIn/"+temporaryStorageArrays+"/"+depotIdIn
						});

                        /*随机单号*/
                        randomOdd();

                        temporaryStorageArrays = [];

                        table.reload('currentTableId',{
                            data:temporaryStorageArrays
                        });

                        /*选择仓库 取消只禁读*/
                        readonlysz();

                        layer.open({
                            type:0,
                            title:'系统提醒',
                            content:'调拨成功!',
                            area: ['200px']
                            //time:2000,
                        });

                        /*删除和修改按钮*/
                        amendAnddelete();
					}
                });

				/*库存调拨的商品表*/
                table.render({
                    elem: '#currentTableId',
                    data: temporaryStorageArrays,
                    height: '390',
                    toolbar: '#toolbarDemo',
                    defaultToolbar: ['filter', 'exports', 'print', {
                        title: '提示',
                        layEvent: 'LAYTABLE_TIPS',
                        icon: 'layui-icon-tips'
                    }],
                    cols: [
                        [{
                            field: 'proId',
                            width: 120,
                            title: '商品编号'
                        }, {
                            field: 'inveDescName',
                            width: 200,
                            title: '商品名称'
                        }, {
                            field: 'inveDescUnit',
                            width: 80,
                            title: '单位'
                        }, {
                            field: 'inveDescSize',
                            width: 120,
                            title: '产品规格'
                        }, {
                            field: 'inveDescBatchNum',
                            title: '产品批号',
                            width: 120
                        }, {
                            field: 'inveDescValidityDate',
                            width: 120,
                            title: '生产日期'
                        }, {
                            field: 'inveDescValidityDate',
                            width: 120,
                            title: '有效期至'
                        }, {
                            field: 'inveDescNum',
                            width: 80,
                            title: '数量'
                        }, {
                            field: 'inveDescManufacturer',
                            width: 130,
                            title: '生产厂商'
                        }, {
                            field: 'inveDescPrice',
                            width: 80,
                            title: '销售'
                        }, {
                            field: 'totalMoney',
                            width: 100,
                            title: '总金额'
                        }]
                    ],done: function (obj) {
                        row = obj.data[surfaceIndex];
                        $('#currentTableId~div tr[data-index='+surfaceIndex+']').addClass('layui-bg-green');
                    }
                });



                /*商品批次信息*/
                var commodityBatchSurface = function () {
                     table.render({
                        elem: '#commodityBatch',
                        url: '/searchCommodityBatch/'+row.proId+'/'+depotName,
                        height: '180',
                        defaultToolbar: ['filter', 'exports', 'print', {
                            title: '提示',
                            layEvent: 'LAYTABLE_TIPS',
                            icon: 'layui-icon-tips'
                        }],
                        cols: [
                            [{
                                field: 'proId',
                                width: 81,
                                title: '商品编号'
                            }, {
                                field: 'inveDescName',
                                width: 81,
                                title: '商品名称'
                            }, {
                                field: 'purStoDate',
                                width: 81,
                                title: '进货日期',
                                templet:function (data){return timeTransform(data.purStoDate)}
                            }, {
                                field: 'inveDescInventoryNum',
                                width: 81,
                                title: '库存数量'
                            }, {
                                field: 'inveDescBatchNum',
                                title: '产品批次',
                                width: 81
                            }, {
                                field: 'inveDescStartDate',
                                width: 81,
                                title: '生产日期',
                                templet:function (data){
                                    $("#inveDescStartDate").val(timeTransform(data.inveDescStartDate));
                                    return timeTransform(data.inveDescStartDate)}
                            }, {
                                field: 'inveDescValidityDate',
                                width: 82,
                                title: '有效日期',
                                templet:function (data){
                                    $("#inveDescValidityDate").val(timeTransform(data.inveDescValidityDate));
                                    return timeTransform(data.inveDescValidityDate)}
                            }]
                        ],done: function (obj) {
							 var commodityBatchindex;
                             for(var i = 0;i<obj.data.length; i++){
                                 if(obj.data[i].inveDescBatchNum == row.inveDescBatchNum){
                                     row = obj.data[i];
                                     commodityBatchindex = i;
                                 }
                             }

							 $("#inveDescValidityDate").val(timeTransform(obj.data[commodityBatchindex].inveDescValidityDate));
                             $('#inveDescStartDate').val(timeTransform(obj.data[commodityBatchindex].inveDescStartDate));
                             $('#commodityBatch~div tr[data-index='+commodityBatchindex+']').addClass('layui-bg-green');

                             var quality  = parseInt((obj.data[commodityBatchindex].inveDescValidityDate -
                                 obj.data[commodityBatchindex].inveDescStartDate)/1000/60/60/24/30)+"个月";
                             $('#quality').val(quality);
                        }
                    });
                }

                /*调出仓库*/
                var depotIdOut = 0;
                /*调入仓库*/
                var depotIdIn = 0;
                /*经办人*/
                var empId = 0;
                /*调拨时间*/
                var allotData = "2022-03-21 - 2022-04-21";
                /*区分时间查询与高级查询*/
                var flag = "advancedQuerybtn";
                /*单据号*/
                var invAllotId = 0;

                /*高级查询按钮*/
				$('#advancedQuerybtn').click(function () {
					depotIdOut = $('#transferOutOfWarehouses~div .layui-this').attr('lay-value');
					depotIdIn = $('#transferIntoWarehouses~div .layui-this').attr('lay-value');
					empId = $('#employees~div .layui-this').attr('lay-value');
					flag = "advancedQuerybtn";
                    invAllotId = 0;
                    /*判断日期是否为空*/
                    if(null == allotData){
                        allotData = "2022-03-21 - 2022-04-21";
                    }
                    table.reload('receiptsParticulars',{
                        url:'/searchInventoryAllocationDescInfo/'+invAllotId
                    });

                    repertoryAllot();
                    $('#receiptsInfo>span:nth-of-type(2)').html("");
                });
				/*调拨时间查询按钮*/
				$('#allotData').click(function () {
					allotData = $('#shijiansan').val();
					flag = "allotData";
                    invAllotId = 0;
                    table.reload('receiptsParticulars',{
                        url:'/searchInventoryAllocationDescInfo/'+invAllotId
                    });
                    repertoryAllot();
                    $('#receiptsInfo>span:nth-of-type(2)').html("");
                });
                /*库存调拨列表所有行单击*/
                table.on('row(repertoryAllot)', function(obj){
                    obj.tr.addClass('layui-bg-green').siblings().removeClass('layui-bg-green');
                    surfaceIndex = obj.tr.attr('data-index');
                    row = obj.data;
                    invAllotId = row.invAllotId;
                    $('#receiptsInfo>span:nth-of-type(2)').html(invAllotId);
                    receiptsMinuteChart();
                });
				/*库存调拨列表*/
			 	var repertoryAllot = function () {
                    table.render({
                        elem: '#repertoryAllot',
                        url: '/searchInventoryAllocationInfo/'+depotIdOut+'/'+depotIdIn+'/'+empId+'/'+allotData+'/'+flag,
                        height: '230',
                        defaultToolbar: ['filter', 'exports', 'print', {
                            title: '提示',
                            layEvent: 'LAYTABLE_TIPS',
                            icon: 'layui-icon-tips'
                        }],
                        cols: [
                            [{
                                field: 'invAllotId',
                                width: 110,
                                title: '调拨单号'
                            }, {
                                field: 'deporNameOut',
                                width: 110,
                                title: '调出仓库'
                            }, {
                                field: 'deporNameIn',
                                width: 110,
                                title: '调入仓库'
                            }, {
                                field: 'invAllotDate',
                                width: 110,
                                title: '调拨日期',
                                templet:function (data){return timeTransform(data.invAllotDate)}
                            }, {
                                field: 'empNamej',
                                title: '经办人',
                                width: 90
                            }, {
                                field: 'empNamec',
                                width: 90,
                                title: '操作员'
                            }, {
                                field: 'invAllotComment',
                                width: 170,
                                title: '备注'
                            }]
                        ]
                    });
                }
                repertoryAllot();

				/*单据详细表*/
				var receiptsMinuteChart = function () {
                    table.render({
                        elem: '#receiptsParticulars',
						id: 'receiptsParticulars',
                        url: '/searchInventoryAllocationDescInfo/'+invAllotId,
                        height: '195',
                        defaultToolbar: ['filter', 'exports', 'print', {
                            title: '提示',
                            layEvent: 'LAYTABLE_TIPS',
                            icon: 'layui-icon-tips'
                        }],
                        cols: [
                            [{
                                field: 'proId',
                                width: 130,
                                title: '商品编号'
                            }, {
                                field: 'invAllotDescProName',
                                width: 160,
                                title: '商品名称'
                            }, {
                                field: 'invAllotDescNum',
                                width: 80,
                                title: '数量'
                            }, {
                                field: 'invAllotDescProUnit',
                                width: 80,
                                title: '单位'
                            }, {
                                field: 'invAllotDescProSize',
                                title: '规格',
                                width: 80
                            }, {
                                field: 'invAllotDescProBatchNum',
                                width: 130,
                                title: '产品编号'
                            }, {
                                field: 'invAllotDescValidityDate',
                                width: 130,
                                title: '有效至期',
                                templet:function (data){return timeTransform(data.invAllotDescValidityDate)}
                            }]
                        ]
                    });
                }
				receiptsMinuteChart();

				// 监听搜索操作
				form.on('submit(data-search-btn)', function(data) {
					var result = JSON.stringify(data.field);
					layer.alert(result, {
						title: '最终的搜索信息'
					});

					//执行搜索重载
					table.reload('currentTableId', {
						page: {
							curr: 1
						},
						where: {
							searchParams: result
						}
					}, 'data');

					return false;
				});

              	/*查询仓库表信息*/
                $.ajax({
                    type:"GET",
                    url:"/searchInventory",
                    success:function (data) {
                        var jsonList = JSON.parse(data);
                        var useitObjOut = $('#transferOutOfWarehouse');
                        var useitObjInt = $('#transferIntoWarehouse');
                        var useitObjOuts = $('#transferOutOfWarehouses');
                        var useitObjInts = $('#transferIntoWarehouses');
                        depotName = jsonList[0].depotName;
                        if(0 != jsonList.length){
                            for(var i = 0;i<jsonList.length; i++){
                                useitObjOut.append(new Option(jsonList[i].depotName,jsonList[i].depotId));
                                useitObjOuts.append(new Option(jsonList[i].depotName,jsonList[i].depotId));
                            }
                            form.render('select');
                        }

                        if(0 != jsonList.length){
                            for(var i = 0;i<jsonList.length; i++){
								if(jsonList[i].depotName != depotName){
                                    useitObjInt.append(new Option(jsonList[i].depotName,jsonList[i].depotId));
                                }
                                useitObjInts.append(new Option(jsonList[i].depotName,jsonList[i].depotId));
                            }
                            form.render('select');
                        }
                    }
                });

                /*查询经办人信息*/
                $.ajax({
                    type:"GET",
                    url:"/searchEmployeeInfo",
                    success:function (data) {
                        var jsonList = JSON.parse(data);
                        var empName = $('#employee');
                        var empId = $('#employees');
                        if(0 != jsonList.length){
                            for(var i = 0;i<jsonList.length; i++){
                                empName.append(new Option(jsonList[i].empName,jsonList[i].empId));
                                empId.append(new Option(jsonList[i].empName,jsonList[i].empId));
                            }
                            form.render('select');
                        }
                    }
                });

                /*根据调出仓库来改变调出仓库下拉列表的名称*/
                form.on('select(watch)', function() {
                    depotName = $('#transferOutOfWarehouse~div .layui-this').attr('lay-value');
                    $.ajax({
                        type:"GET",
                        url:"/searchInventory",
                        success:function (data) {
                            var jsonList = JSON.parse(data);
                            var useitObjInt = $('#transferIntoWarehouse');

                            if(0 != jsonList.length){
                                useitObjInt.html("");
                                for(var i = 0;i<jsonList.length; i++){
                                    if(jsonList[i].depotId != depotName){
                                        useitObjInt.append(new Option(jsonList[i].depotName,jsonList[i].depotId));
                                    }
                                }
                                form.render('select');
                            }
                        }
                    });
                });


				/**
				 * toolbar监听事件 增删改
				 */
                table.on('toolbar(currentTableId)', function(obj) {
                    if(obj.event === 'add') { // 监听添加操作
                        /*attr('lay-value')  获取value的值*/
                        depotName = $('#transferOutOfWarehouse~div .layui-this').attr('lay-value');
                        var index = layer.open({
                            title: '添加商品',
                            type: 2,
                            shade: 0.2,
                            maxmin: true,
                            shadeClose: true,
                            area: ['100%', '100%'],
                            content: 'repertorAllotAdd.html',
                        });
                        $(window).on("resize", function() {
                            layer.full(index);
                        });
                    }

                    /*修改按钮*/
                    if(obj.event === 'modifyProduct'){
                        if(temporaryStorageArrays.length > 0){
                            addhotd(row);
                            commodityBatchSurface();
                            temporaryStorageArrays[surfaceIndex] = form.val('toolbarDemo');
                        }
                    }

                    /*删除按钮*/
                    if(obj.event === 'deleteItem'){
                        if(temporaryStorageArrays.length > 0){
                            index = layer.open({
                                type: 1,
                                title: '系统提示',
                                content: $('#whetherDelete'),
                                area: ["300px", "190px"]
                            });
                            /*是删除*/
                            $('#whetherDelete>div:nth-of-type(2)>button:nth-of-type(1)').click(function () {
                                layer.close(index);
                                temporaryStorageArrays.splice(surfaceIndex,1);
                                /*删除后 设置选择首行*/
                                surfaceIndex = 0;
                                table.reload('currentTableId',{
                                    data:temporaryStorageArrays
                                });
                                /*仓库的选中框禁读*/
                                readonlysz();
                                /*删除和修改按钮*/
                                amendAnddelete();

                                $(this).unbind();
                                $('#whetherDelete>div:nth-of-type(2)>button:nth-of-type(2)').unbind();
                            });
                            /*否 删除*/
                            $('#whetherDelete>div:nth-of-type(2)>button:nth-of-type(2)').click(function () {
                                layer.close(index);
                                $(this).unbind();
                                $('#whetherDelete>div:nth-of-type(2)>button:nth-of-type(1)').unbind();
                            });
                        }
					}
                });


 				table.on('tool(currentTableFilter)', function(obj) {
					var data = obj.data;
					if(obj.event === 'edit') {
						var index = layer.open({
							title: '编辑用户',
							type: 2,
							shade: 0.2,
							maxmin: true,
							shadeClose: true,
							area: ['100%', '100%'],
							content: '../page/table/edit.html',
						});
						$(window).on("resize", function() {
							layer.full(index);
						});
						return false;
					} else if(obj.event === 'delete') {
						layer.confirm('真的删除行么', function(index) {
							obj.del();
							layer.close(index);
						});
					}
				});

 				/*删除和修改按钮*/
                var amendAnddelete = function () {
                    if(temporaryStorageArrays.length > 0){
                        $('button[lay-event=deleteItem]').css('display','inline-block');
                        $('button[lay-event=modifyProduct]').css('display','inline-block');
                    }else{
                        $('button[lay-event=deleteItem]').css('display','none');
                        $('button[lay-event=modifyProduct]').css('display','none');
                    }

                }
                amendAnddelete();

                /*调入仓库设置禁读*/
                readonlysz = function () {
                    if(temporaryStorageArrays.length > 0){
                        $('#transferOutOfWarehouse').attr("disabled",true);
                    }else{
                        $('#transferOutOfWarehouse').attr("disabled",false);
                        form.render('select');
					}
                }
                readonlysz();


                /*日期格式转换*/
                function timeTransform(date) {
                    var date = new Date(date);
                    var year = date.getFullYear();
                    var moth = date.getMonth() + 1;
                    var day = date.getDate();
                    return year + "-" + moth + "-" + day;
                }

                //这个是用于处理月份没有两位数时，在前面加一个“0”
                function doHandleMonth(month){
                    var m = month;
                    if(month.toString().length == 1){
                        m = "0" + month;
                    }
                    return m;
                }
                function getDay(day){
                    var today = new Date();
                    var targetday_milliseconds=today.getTime() + 1000*60*60*24*day;
                    today.setTime(targetday_milliseconds); //注意，这行是关键代码
                    var tYear = today.getFullYear();
                    var tMonth = today.getMonth();
                    var tDate = today.getDate();
                    tMonth = doHandleMonth(tMonth + 1);
                    tDate = doHandleMonth(tDate);
					return tYear+"-"+tMonth+"-"+tDate;
                }
			});
		</script>


		<!--js代码-->
		<script>
            layui.use(['form', 'table', 'table'], function() {
                var form = layui.form,
                    layer = layui.layer,
                    $ = layui.$;
				var table = layui.table;



            });
		</script>

	</body>

</html>